#! /usr/bin/env python
# -*- coding: utf-8 -*-

from qcloudsms_py import SmsSingleSender, SmsMultiSender
from qcloudsms_py.httpclient import HTTPError


class SMS(object):
    """
    腾讯云短信
    """

    def __init__(self, sms_id, sms_key):
        self.ssender = SmsSingleSender(sms_id, sms_key)
        self.msender = SmsMultiSender(sms_id, sms_key)

    def sendSingleMsg(self, ph_num, template_id, params, sign, **kwargs):
        """
        发送单条短信
        :param ph_num: 手机号 str
        :param template_id: 模板id Str
        :param params: 短信参数List[Str]
        :param sign: 签名
        :param kwargs:
        :return:
        """
        try:
            result = self.ssender.send_with_param(86, ph_num,
                                                  template_id, params,
                                                  sign=sign, extend="", ext="", **kwargs)
            return result
        except HTTPError as e:
            print(e)
        except Exception as e:
            print(e)

        # print(result)

    def sendMultiMsg(self, ph_nums, template_id, params, sign, **kwargs):
        """
        发送多条短信
        :param ph_nums: 手机号 List(str)
        :param template_id: 模板id Str
        :param params: 短信参数List[Str]
        :param sign: 签名
        :param kwargs:
        :return:
        """
        try:
            result = self.msender.send_with_param(86, ph_nums,
                                                  template_id, params,
                                                  sign=sign, extend="", ext="", **kwargs)
            return result

        except HTTPError as e:
            print(e)
        except Exception as e:
            print(e)

        # print(result)
